package com.aaa.hospital.ManagementEnd.controller;


import com.aaa.hospital.Configurationterminal.pojo.Admintab;
import com.aaa.hospital.ManagementEnd.service.AdmintabService;
import com.alibaba.fastjson.JSONObject;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.websocket.server.PathParam;
import java.util.List;

@Controller
@RequestMapping("/admin")
public class AdmintabController {

    @Autowired
    private AdmintabService admintabService;



    @RequestMapping(value = "/admin_query",method = RequestMethod.GET)
    @ResponseBody
    public String admin_query(){
        JSONObject json = new JSONObject();
        List<Admintab> admintabs = admintabService.admin_query();
        Object objData=JSONObject.toJSON(admintabs);
        json.put("code", 0);
        json.put("msg", "");
        json.put("count",admintabs.size());
        json.put("data",objData);
        return json.toJSONString();
    }




    @RequestMapping(value = "/admin_insert",method = RequestMethod.GET)
    @ResponseBody
    public boolean  admin_insert(Admintab admintab){

        return admintabService.admin_insert(admintab);

    }

    @RequestMapping("/admin_update")
    @ResponseBody
    public Boolean  admin_update(Admintab admintab){

        return admintabService.admin_update(admintab);
    }

    @RequestMapping("/admin_delete")
    @ResponseBody
    public Boolean  admin_delete(@PathParam("id") Integer id){

        return admintabService.admin_delete(id);
    }



    @RequestMapping("/limitAll")
    @ResponseBody
    public String limitAll(@Param("id") String id, @Param("name") String name){
        JSONObject json = new JSONObject();
        List<Admintab> admintabs = admintabService.limitAll(id, name);
        Object objData=JSONObject.toJSON(admintabs);
        json.put("code", 0);
        json.put("msg", "");
        json.put("count",admintabs.size());
        json.put("data",objData);
        return json.toJSONString();
    }



}
